package ihm;

import java.awt.Color;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JOptionPane;

import batailleNavale.ClientIHM;
import batailleNavale.Constantes;

/**
 * @author LE DOAN GIANG NGOC
 *
 */
public class PanelJouer extends PanelGrille implements MouseListener {
	private Jeu parent;
	private ClientIHM cli;
	private boolean droitJouer;
	private char coul = ' ';
	private int xTir;
	private int yTir;
	
	
	public Jeu getParent() {
		return parent;
	}

	public void setParent(Jeu parent) {
		this.parent = parent;
	}

	public int getxTir() {
		return xTir;
	}

	public void setxTir(int xTir) {
		this.xTir = xTir;
	}

	public int getyTir() {
		return yTir;
	}

	public void setyTir(int yTir) {
		this.yTir = yTir;
	}

	public ClientIHM getCli() {
		return cli;
	}

	public char getCoul() {
		return coul;
	}

	public void setCoul(char coul) {
		this.coul = coul;
	}

	public void setDroitJouer(boolean droitJouer) {
		this.droitJouer = droitJouer;
	}

	public boolean isDroitJouer() {
		return droitJouer;
	}

	public PanelJouer(Jeu parent, boolean estPerso) {
		super(estPerso);
		this.parent = parent;
		this.droitJouer = false;
	}

	public void setCli(ClientIHM cli) {
		this.cli = cli;
	}

	@Override
	public void mouseClicked(MouseEvent mr) {

		if (droitJouer) {
			xTir = mr.getComponent().getX();
			yTir = mr.getComponent().getY();
			int x  = (int)(Math.round(mr.getComponent().getX()/30.0));
			int y  = (int)(Math.round(mr.getComponent().getY()/25.0));
			
			cli.getToServ().println(x);
			cli.getToServ().flush();
			cli.getToServ().println(y);
			cli.getToServ().flush();
			droitJouer = false;
		}
	}

	@Override
	public void mouseEntered(MouseEvent me) {
		Point mousePosition = getMousePosition();
		parent.setLblInfo("Case : " + getCaseX(mousePosition) + " " + getCaseY(mousePosition));
	}

	@Override
	public void mouseExited(MouseEvent mex) {
		parent.setLblInfo(" ");
	}
	
}